package com.example.food;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.example.food.fragment.FocusFragment;
import com.example.food.fragment.HomePageFragment;
import com.example.food.fragment.MineFragment;
import com.example.food.fragment.OrderFragment;
import com.example.home.R;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class TakeoutMainActivity extends AppCompatActivity {
    private LinearLayout YeMian;
    private BottomNavigationView botview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_takeout_main);
        initView();
        FocusFragment focusFragment = new FocusFragment();
        HomePageFragment homePageFragment = new HomePageFragment();
        MineFragment mineFragment = new MineFragment();
        OrderFragment orderFragment = new OrderFragment();

        getSupportFragmentManager().beginTransaction().replace(R.id.YeMian,homePageFragment).commit();
        botview.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.home_page:
                        getSupportFragmentManager().beginTransaction().replace(R.id.YeMian, homePageFragment).commit();
                        break;
                    case R.id.focus:
                        getSupportFragmentManager().beginTransaction().replace(R.id.YeMian, focusFragment).commit();
                        break;
                    case R.id.mine:
                        getSupportFragmentManager().beginTransaction().replace(R.id.YeMian, mineFragment).commit();
                        break;
                    case R.id.order:
                        getSupportFragmentManager().beginTransaction().replace(R.id.YeMian, orderFragment).commit();
                        break;

                }
                return true;
            }
        });
    }

    private void initView() {
        YeMian = findViewById(R.id.YeMian);
        botview = findViewById(R.id.botview);

    }
}